package com.elong.businesstravel.modules.orders;

import java.util.ArrayList;
import java.util.List;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;

import com.android.support.jhf.androidpulltorefresh.library.PullToRefreshBase;
import com.android.support.jhf.androidpulltorefresh.library.PullToRefreshListView;
import com.elong.businesstravel.R;
import com.elong.businesstravel.base.baseactivity.BaseActivity;
import com.elong.businesstravel.entitys.OrderInfo;
import com.elong.businesstravel.modules.orders.adapter.OrdersListAdapter;
/**
 * 订单列表页
 * @author lenovo
 *
 */
public class OrdersListActivity extends BaseActivity {
	
	private PullToRefreshListView mPullToRefreshListView;
	private OrdersListAdapter mOrdersListAdapter;
	
	private List<OrderInfo> mOrderInfos = new ArrayList<OrderInfo>();

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_orders_list);

		init();
	}
	
	@Override
	protected void init() {
		mPullToRefreshListView = (PullToRefreshListView)findViewById(R.id.listView);
		mOrdersListAdapter = new OrdersListAdapter(mContext, mOrderInfos);
		mPullToRefreshListView.setAdapter(mOrdersListAdapter);
		
		setListener();
	}
	
	@Override
	protected void setListener() {
		mPullToRefreshListView.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {
				
			}
		});
		
		mPullToRefreshListView.setOnRefreshListener(new PullToRefreshBase.OnRefreshListener2<ListView>() {

			@Override
			public void onPullDownToRefresh(PullToRefreshBase<ListView> refreshView) {
				mHandler.sendEmptyMessage(0);
			}

			@Override
			public void onPullUpToRefresh(PullToRefreshBase<ListView> refreshView) {
				mHandler.sendEmptyMessage(0);
			}
		});
	}
	
	private Handler mHandler = new Handler(new Handler.Callback() {
		
		@Override
		public boolean handleMessage(Message msg) {
			switch (msg.what) {
			case 0:{
				mPullToRefreshListView.onRefreshComplete();
				break;
			}
			default:
				break;
			}
			return false;
		}
	});

}
